package io.kiki.stack.netty.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * Protocol code based decoder, the main decoder for a certain protocol, which is lead by one or multi bytes (magic code).
 * <p>
 * Notice: this is not stateless, can not be noted as {@link io.netty.channel.ChannelHandler.Sharable}
 */

@Slf4j
@Setter
@Getter
public class ProtocolCodeBasedDecoder extends AbstractBatchDecoder {


    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> out) throws Exception {
        in.markReaderIndex();

        Protocol protocol = ProtocolImpl.protocol;
        protocol.getDecoder().decode(channelHandlerContext, in, out);
    }
}
